package com.zzl.study.demo.domain;

import com.zzl.study.demo.enums.Priority;
import com.zzl.study.demo.enums.Status;
import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

import static com.zzl.study.demo.utils.DateTimeUtil.toDateString;

/**
 * 待办事项实体对象
 *
 * @author: zhangzl
 * @date: 2025/10/14 14:49
 * @version: 1.0
 */
@Data
@Entity
@Table(name = "todo_items")
public class TodoItem {

    /**
     * 主键ID
     */
    @Id
    private Integer id;

    /**
     * 标题
     */
    @Column(name = "title")
    private String title;

    /**
     * 描述
     */
    @Column(name = "description")
    private String description;

    /**
     * 截止时间
     */
    @Column(name = "deadline")
    private LocalDateTime deadline;

    /**
     * 状态
     */
    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    private Status status;

    /**
     * 优先级
     */
    @Column(name = "priority")
    @Enumerated(EnumType.STRING)
    private Priority priority;

    /**
     * 创建时间
     */
    @Column(name = "created_at")
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    public String formatString(int index) {
        return String.format("""
               %d. 代办标题：%s
                   待办描述：%s
                   截止时间：%s
                   当前状态：%s
                   优先级：%s
                   创建时间：%s
               
               """, index, this.title, this.description, toDateString(this.deadline), this.status.getDescription(), this.priority.getDescription(), toDateString(this.createdAt));
    }

}
